<template>
  <div class="login-group" style="position:absolute;top: 0;">
    <div class="left-box">
      <div class="left-bg-img"></div>
    </div>
    <div class="right-box">
      <div class="form-box">
        <p class="tit">用户登录</p>
        <a-form-model :model="loginForm" ref="loginFormRef" :rules="rules">
          <a-form-model-item label="账号" prop="userName">
            <a-input v-model="loginForm.userName"/>
          </a-form-model-item>
          <a-form-model-item label="密码" prop="password">
            <a-input-password v-model="loginForm.password"/>
          </a-form-model-item>
          <a-form-model-item>
            <a-button class="login-form-button" type="primary" @click="submitForm">登录</a-button>
          </a-form-model-item>
        </a-form-model>
      </div>
    </div>
  </div>
</template>

<script>
import rulesData from '@/utils/rules'
import api from '@/api/login'

export default {
  name: 'LoginView',
  data () {
    return {
      codeData: {},
      loginForm: {
        userName: '',
        password: '',
      },
      rules: {
        userName: [
          rulesData.required('请输入账号', 'change'),
          rulesData.whitespace('请输入账号', 'change'),
        ],
        password: [
          rulesData.required('请输入密码'),
          rulesData.whitespace('请输入密码'),
        ],
      },
      showErrTip: false,
    }
  },
  methods: {
    // 登录
    submitForm () {
      this.$refs.loginFormRef.validate(valid => {
        if (valid) {
          let params = {
            ...this.loginForm,
          }
          console.log(params)
          api.login(params).then(res => {
            if (res.status == 200) {
              console.log('94',res)
              const data=res.data
              localStorage.setItem('userId', data[0].userId)
              localStorage.setItem('token', data[0].token)
              localStorage.setItem('userName',data[0].userName)
              this.$router.push({path: '/'})
            }
          })
        }
      })
    },
    initStoreInfo () {
    },
    logout () {
      const userId=localStorage.getItem('userId')
      api.logout({id:userId }).then(res => {
        if (res.data.status == 0) {
          localStorage.removeItem('userId')
          localStorage.removeItem('token')
        }
      })
    }
  },
  created() {
    this.initStoreInfo()
  },
  beforeCreate () {
  }
}

</script>

<style lang="less" scoped>

/deep/div .ant-page-header .ant-page-header-ghost{
  height:0 !important;
  padding: 0 !important;
  display: none !important;
}
.login-group {
  background-color: #ffffff;
  width: 100%;
  height: 100%;
  min-height: 600px;
  position: relative;
  .code-box {
    position: relative;
    img {
      position: absolute;
      z-index: 1;
      width: 133px;
      right: 5px;
      height: 34px;
      top: 3px;
    }
    input {
      padding-right: 120px;
    }
  }
  .left-box {
    position: absolute;
    width: 576px;
    height: 100%;
    background: linear-gradient( to bottom,#707DE0,#3D47BE);
    .left-bg-img {
      width: 576px;
      height: 100%;
      background-size: 576px 900px;
    }
  }

  .right-box {
    position: absolute;
    right: 0;
    top: 0;
    width: calc(~'100% - 576px');
    height: 100%;
    .form-box{
      position: absolute;
      left: 50%;
      top: 50%;
      margin-left: -261px;
      margin-top: -241px;
      width: 432px;
      min-height: 482px;
      background: #FFFFFF;
      border: 1px solid rgba(227,230,235,1);
      box-shadow: 0px 0px 26px 0px rgba(10,31,68,0.08);
      border-radius: 8px;
      padding: 36px 40px;


      .login-form-button {
        height: 40px;
        width: 100%;
        font-size: 16px;
        line-height: 40px;
        color: #FFFFFF;
        text-align: center;
        font-weight: 400;
        margin-top: 16px;
      }
      .tit {
        margin-bottom: 24px;
        font-size: 32px;
        line-height: 32px;
        color: #1B1E22;
        letter-spacing: 0;
        font-weight: 500;
      }
      .error-tip {
        display: none;
        box-sizing: border-box;
        padding-left: 14px;
        height: 40px;
        background: #FFF6F5;
        border: 1px solid rgba(250,95,95,1);
        border-radius: 4px;
        font-size: 14px;
        line-height: 40px;
        color: #FA5F5F;
        text-align: left;
        font-weight: 400;
        margin-bottom: 16px;
        .show {
          display: block;
        }
        span {
          font-size: 20px;
          position: relative;
          top: 4px;
          margin-right: 8px;
        }
      }
      .tip {
        margin: 0;
        text-align: center;
        font-size: 14px;
        color: rgba(27,30,34,0.65);
        letter-spacing: 0;
        line-height: 20px;
        font-weight: 400;
        a {
          color: #4487F7;
        }
      }
    }
  }
}
input {
  height: 40px;
}
/deep/.ant-input-affix-wrapper .ant-input:not(:last-child) {
  height: 40px;
}
/deep/.ant-form-item {
  margin-bottom: 16px;
}
/deep/.ant-form-item-label {
  line-height: 20px;
  margin-bottom: 7px;
}
/deep/.ant-form-item-required:before {
  display: none;
}
/deep/.ant-form-item-required:after {
  display: inline-block;
  margin-right: 4px;
  color: #f5222d;
  font-size: 14px;
  font-family: SimSun, sans-serif;
  line-height: 1;
  content: '*';
}
/deep/.ant-form-explain {
  margin-top: 4px;
}

</style>

